package hk.meiyan.com.kotlincode.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import hk.meiyan.com.kotlincode.R


/**
 * Created by 54hk on 2018/5/25.
 */
class MyAdapter(context:Context ,array:List<Bean>) : BaseAdapter() {
    var array:List<Bean> = array
    var context:Context = context

    override fun getItem(p0: Int): Any {
        return array.get(p0)
    }

    override fun getItemId(p0: Int): Long {
      return p0.toLong()
    }

    override fun getCount(): Int {
        return array.size
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var mView:View
        var viewholder:ViewHolder
        if(p1 == null){
            mView =  LayoutInflater.from(context).inflate(R.layout.adapter_item,null)
            viewholder = ViewHolder(mView)
            mView.setTag(viewholder)
        }else{
            mView = p1;
            viewholder = mView.getTag() as ViewHolder
        }
        viewholder.textView.setText(array.get(p0).name + ":这是我的")

        return mView
    }
    class ViewHolder(var mViews:View){
        var textView:TextView = mViews.findViewById(R.id.item_txt)
    }
}

